﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="kapitaliOmanikType_v3", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(KapitaliOmanikTypeV3))]
    public class KapitaliOmanikTypeV3Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKapitaliOmanikTypeV3 clazz;
        
        public KapitaliOmanikTypeV3Serializer(IKapitaliOmanikTypeV3 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            for (int x = 0; ((clazz.Isikud != null) 
                        && (x < clazz.Isikud.Count)); x = (x + 1)) {
                if (clazz.Isikud[x]!=null) {
                    Writer.WriteStartElement("isikud");
                    global::Xtee.Core.SerializationMetadata metaIsikud = this.GetMetaData(clazz.Isikud[x]);
                    Writer.WriteTypeAttribute(metaIsikud.TypeQualifiedName.Namespace, metaIsikud.TypeQualifiedName.Name);
                    metaIsikud.NewSerializer(clazz.Isikud[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
            if (clazz.Osa!=null) {
                Writer.WriteStartElement("osa");
                global::Xtee.Core.SerializationMetadata metaOsa = this.GetMetaData(clazz.Osa);
                Writer.WriteTypeAttribute(metaOsa.TypeQualifiedName.Namespace, metaOsa.TypeQualifiedName.Name);
                metaOsa.NewSerializer(clazz.Osa).WriteXml(Writer);
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="isikud") {
                clazz.Isikud = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IIsikTypeV3>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "isikud")); ) {
                    if ((Reader.IsElementNil() == false)) {
                        global::Xtee.Core.SerializationMetadata metaIsikud = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IIsikTypeV3>(Reader, "isikType_v3", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IIsikTypeV3 item = metaIsikud.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IIsikTypeV3>();
                        clazz.Isikud.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("isikud");
                            metaIsikud.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    else {
                        clazz.Isikud.Add(null);
                        Reader.Skip();
                    }
                }
            }
            if (Reader.LocalName=="osa") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kapitaliOmanikType_v3>osa");
                }
                global::Xtee.Core.SerializationMetadata metaOsa = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMurdType>(Reader, "murdType", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Osa = metaOsa.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMurdType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("osa");
                    metaOsa.NewSerializer(clazz.Osa).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
